<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>$NAME</title>
    <link rel="stylesheet" type="text/css" href="csound.css" />
    <meta name="generator" content="DocBook XSL Stylesheets V1.78.1" />
    <link rel="home" href="index.html" title="The Canonical Csound Reference Manual" />
    <link rel="up" href="OpcodesTop.html" title="Orchestra Opcodes and Operators" />
    <link rel="prev" href="ifndef.html" title="#ifndef" />
    <link rel="next" href="modulus.html" title="%" />
  </head>
  <body>
    <div class="navheader">
      <table width="100%" summary="Navigation header">
        <tr>
          <th colspan="3" align="center">$NAME</th>
        </tr>
        <tr>
          <td width="20%" align="left"><a accesskey="p" href="ifndef.html">Prev</a> </td>
          <th width="60%" align="center">Orchestra Opcodes and Operators</th>
          <td width="20%" align="right"> <a accesskey="n" href="modulus.html">Next</a></td>
        </tr>
      </table>
      <hr />
    </div>
    <div class="refentry">
      <a id="dollar"></a>
      <div class="titlepage"></div>
      <a id="IndexDollarMacros" class="indexterm"></a>
      <a id="IndexDollarOrch" class="indexterm"></a>
      <a id="IndexDollar" class="indexterm"></a>
      <div class="refnamediv">
        <h2>
          <span class="refentrytitle">$NAME</span>
        </h2>
        <p>$NAME — 
      Calls a defined macro.
                      </p>
      </div>
      <div class="refsect1">
        <a id="idp87525104"></a>
        <h2>Description</h2>
        <p>
      Macros are textual replacements which are made in the orchestra as it is being read.  The macro system in Csound is a very simple one, and uses the characters # and $ to define and call macros. This can save typing, and can lead to a coherent structure and consistent style.  This is similar to, but independent of, the <a class="link" href="ScoreMacros.html" title="Score Macros"><em class="citetitle">macro system in the score language</em></a>.
    </p>
        <p>
      <span class="emphasis"><em>$NAME</em></span> -- calls a defined macro. To use a macro, the name is used following a $ character. The name is terminated by the first character which is neither a letter nor a number. If it is necessary for the name not to terminate with a space, a period, which will be ignored, can be used to terminate the name. The string, <span class="emphasis"><em>$NAME</em></span>., is replaced by the replacement text from the definition. The replacement text can also include macro calls.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp87529552"></a>
        <h2>Syntax</h2>
        <pre class="synopsis"><span class="command"><strong>$NAME</strong></span> </pre>
      </div>
      <div class="refsect1">
        <a id="idp87531632"></a>
        <h2>Initialization</h2>
        <p>
      <span class="emphasis"><em># replacement text #</em></span> --  The replacement text is any character string (not containing a #) and can extend over mutliple lines. The replacement text is enclosed within the # characters, which ensure that additional characters are not inadvertently captured.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp87533760"></a>
        <h2>Performance</h2>
        <p>
      Some care is needed with textual replacement macros, as they can sometimes do strange things.  They take no notice of any meaning, so spaces are significant. This is why, unlike the C programming language, the definition has the replacement text surrounded by # characters. Used carefully, this simple macro system is a powerful concept, but it can be abused.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp87534816"></a>
        <h2>Examples</h2>
        <p>
      Here is an example of the calling a macro. It uses the file <a class="ulink" href="examples/define.csd" target="_top"><em class="citetitle">define.csd</em></a>.

      </p>
        <div class="example">
          <a id="idp87537504"></a>
          <p class="title">
            <strong>Example 18. An example of the calling a macro.</strong>
          </p>
          <div class="example-contents">
            <p>See the sections <a class="link" href="UsingRealTime.html" title="Real-Time Audio"><em class="citetitle">Real-time Audio</em></a> and <a class="link" href="CommandFlags.html" title="Csound command line"><em class="citetitle">Command Line Flags</em></a> for more information on using command line flags.</p>
            <pre class="programlisting">
<span class="csdtag">&lt;CsoundSynthesizer&gt;</span>
<span class="csdtag">&lt;CsOptions&gt;</span>
<span class="comment">; Select audio/midi flags here according to platform</span>
<span class="comment">; Audio out   Audio in    No messages</span>
-odac           -iadc     -d     <span class="comment">;;;RT audio I/O</span>
<span class="comment">; For Non-realtime ouput leave only the line below:</span>
<span class="comment">; -o define.wav -W ;;; for file output any platform</span>
<span class="csdtag">&lt;/CsOptions&gt;</span>
<span class="csdtag">&lt;CsInstruments&gt;</span>

<span class="comment">; Initialize the global variables.</span>
<span class="ohdr">sr</span> <span class="op">=</span> 44100
<span class="ohdr">kr</span> <span class="op">=</span> 4410
<span class="ohdr">ksmps</span> <span class="op">=</span> 10
<span class="ohdr">nchnls</span> <span class="op">=</span> 1

<span class="comment">; Define the macros.</span>
<span class="omacro">#define</span> VOLUME #5000#
<span class="omacro">#define</span> FREQ #440#
<span class="omacro">#define</span> TABLE #1#

<span class="comment">; Instrument #1</span>
<span class="oblock">instr</span> 1
  <span class="comment">; Use the macros.</span>
  <span class="comment">; This will be expanded to "a1 oscil 5000, 440, 1".</span>
  a1 <span class="opc">oscil</span> $VOLUME, $FREQ, $TABLE

  <span class="comment">; Send it to the output.</span>
  <span class="opc">out</span> a1
<span class="oblock">endin</span>


<span class="csdtag">&lt;/CsInstruments&gt;</span>
<span class="csdtag">&lt;CsScore&gt;</span>

<span class="comment">; Define Table #1 with an ordinary sine wave.</span>
<span class="stamnt">f</span> 1 0 32768 10 1 
         
<span class="comment">; Play Instrument #1 for two seconds.</span>
<span class="stamnt">i</span> 1 0 2
<span class="stamnt">e</span>


<span class="csdtag">&lt;/CsScore&gt;</span>
<span class="csdtag">&lt;/CsoundSynthesizer&gt;</span>
</pre>
          </div>
        </div>
        <p><br class="example-break" />

      Its output should include lines like this:
      </p>
        <pre class="screen">
Macro definition for VOLUME
Macro definition for CPS
Macro definition for TABLE</pre>
        <p>
    </p>
        <p>
      Here is an example of the calling a macro with arguments. It uses the file <a class="ulink" href="examples/define_args.csd" target="_top"><em class="citetitle">define_args.csd</em></a>.

      </p>
        <div class="example">
          <a id="idp87543648"></a>
          <p class="title">
            <strong>Example 19. An example of the calling a macro with arguments.</strong>
          </p>
          <div class="example-contents">
            <pre class="programlisting">
<span class="csdtag">&lt;CsoundSynthesizer&gt;</span>
<span class="csdtag">&lt;CsOptions&gt;</span>
<span class="comment">; Select audio/midi flags here according to platform</span>
<span class="comment">; Audio out   Audio in    No messages</span>
-odac           -iadc     -d     <span class="comment">;;;RT audio I/O</span>
<span class="comment">; For Non-realtime ouput leave only the line below:</span>
<span class="comment">; -o define_args.wav -W ;;; for file output any platform</span>
<span class="csdtag">&lt;/CsOptions&gt;</span>
<span class="csdtag">&lt;CsInstruments&gt;</span>

<span class="comment">; Initialize the global variables.</span>
<span class="ohdr">sr</span> <span class="op">=</span> 44100
<span class="ohdr">kr</span> <span class="op">=</span> 4410
<span class="ohdr">ksmps</span> <span class="op">=</span> 10
<span class="ohdr">nchnls</span> <span class="op">=</span> 1

<span class="comment">; Define the oscillator macro.</span>
<span class="omacro">#define</span> OSCMACRO(VOLUME'FREQ'TABLE) #oscil $VOLUME, $FREQ, $TABLE#

<span class="comment">; Instrument #1</span>
<span class="oblock">instr</span> 1
  <span class="comment">; Use the oscillator macro.</span>
  <span class="comment">; This will be expanded to "a1 oscil 5000, 440, 1".</span>
  a1 $OSCMACRO(5000'440'1)

  <span class="comment">; Send it to the output.</span>
  <span class="opc">out</span> a1
<span class="oblock">endin</span>


<span class="csdtag">&lt;/CsInstruments&gt;</span>
<span class="csdtag">&lt;CsScore&gt;</span>

<span class="comment">; Define Table #1 with an ordinary sine wave.</span>
<span class="stamnt">f</span> 1 0 32768 10 1 
         
<span class="comment">; Play Instrument #1 for two seconds.</span>
<span class="stamnt">i</span> 1 0 2
<span class="stamnt">e</span>


<span class="csdtag">&lt;/CsScore&gt;</span>
<span class="csdtag">&lt;/CsoundSynthesizer&gt;</span>
</pre>
          </div>
        </div>
        <p><br class="example-break" />

      Its output should include a line like this:
      </p>
        <pre class="screen">
Macro definition for OSCMACRO</pre>
        <p>
    </p>
      </div>
      <div class="refsect1">
        <a id="idp87546368"></a>
        <h2>See Also</h2>
        <p>
      <a class="link" href="define.html" title="#define"><em class="citetitle">#define</em></a>,
      <a class="link" href="undef.html" title="#undef"><em class="citetitle">#undef</em></a>
    </p>
      </div>
      <div class="refsect1">
        <a id="idp87549472"></a>
        <h2>Credits</h2>
        <p>
      </p>
        <table border="0" summary="Simple list" class="simplelist">
          <tr>
            <td>Author: John ffitch</td>
          </tr>
          <tr>
            <td>University of Bath/Codemist Ltd.</td>
          </tr>
          <tr>
            <td>Bath, UK</td>
          </tr>
          <tr>
            <td>April, 1998</td>
          </tr>
        </table>
        <p>
    </p>
        <p>Examples written by Kevin Conder.</p>
        <p>New in Csound version 3.48</p>
      </div>
    </div>
    <div class="navfooter">
      <hr />
      <table width="100%" summary="Navigation footer">
        <tr>
          <td width="40%" align="left"><a accesskey="p" href="ifndef.html">Prev</a> </td>
          <td width="20%" align="center">
            <a accesskey="u" href="OpcodesTop.html">Up</a>
          </td>
          <td width="40%" align="right"> <a accesskey="n" href="modulus.html">Next</a></td>
        </tr>
        <tr>
          <td width="40%" align="left" valign="top">#ifndef </td>
          <td width="20%" align="center">
            <a accesskey="h" href="index.html">Home</a>
          </td>
          <td width="40%" align="right" valign="top"> %</td>
        </tr>
      </table>
    </div>
  </body>
</html>
